import { request } from "@/http/axios"
import * as XLSX from "xlsx";
export function FileDownloadFiaName(fileName) {
  const url = `upload/downloadFile?fileName=${encodeURIComponent(fileName)}`;
  return request({
    url: url,
    method: 'get',
    responseType: 'blob',
  })
}

export function AuditsOpinion(opinionList){
  return request({
    url: '/audits/opinionList',
    method: "post",
    data: {
      opinionList: opinionList
    }
  })
}



export function projectTypePage(form, pageSize, pageNum) {
  return request({
    url: 'projectType/projectTypePage',
    method: 'post',
    data: {
      pageSize: pageSize,
      pageNum: pageNum,
      projectType: form.projectType,
      creator: form.username,
    }
  })
}
export function projectTypeDelects(Ids) {
  return request({
    url: 'projectType/projectTypeDelects',
    method: 'post',
    data: {
      Ids: Ids
    }
  })
}
export function projectTypeAdd(projectType,usernmae){
  return request({
    url: '/projectType/projectTypeAdd',
    method: "post",
    data: {
      projectType: projectType,
      creator: usernmae
    }
  })
}
export function projectTypeEdit(form,username) {
  return request({
    url: 'projectType/projectTypeEdit',
    method: 'post',
    data: {
      id:form.id,
      projectType: form.projectType,
      modifier: username
    }
  })
}
export function projectTypeAdds(fileName,usernmae) {
  return request({
    url: 'projectType/projectTypeAdds',
    method: 'post',
    data: {
      fileName: fileName,
      creator: usernmae
    }
  })
}

//检测项目名称是否存在
export function checkProjectType(projectType) {
  return request({
    url: `projectType/projectType?projectType=${encodeURIComponent(projectType)}`,
    method: 'get',
  })
  }

  //导出数据表格
export function exportFileExcel(data) {
    let tableData = [
      ['序号', '项目类型', '创建人', '修改人', '创建时间', "修改时间"]//导出表头
    ] // 表格表头
    data.forEach((item, index) => {
      let rowData = []
      //导出内容的字段
      rowData = [
        index + 1,
        item.projectType,
        item.creator,
        item.modifier,
        item.createTime,
        item.updateTime
      ]
      tableData.push(rowData)
    })
    let workSheet = XLSX.utils.aoa_to_sheet(tableData);
    let bookNew = XLSX.utils.book_new();
    XLSX.utils.book_append_sheet(bookNew, workSheet, '作品名称') // 工作簿名称
    let name = '项目类型数据' + timeFormats() + '.xlsx'
    XLSX.writeFile(bookNew, name) // 保存的文件名
}
export function timeFormats() {
  let time = new Date();
  let year = time.getFullYear();
  let month = time.getMonth() + 1;
  let date = time.getDate();
  let hours = time.getHours();
  let minutes = time.getMinutes();
  let seconds = time.getSeconds();
  return year + '-' + addZero(month) + '-' + addZero(date) + ' ' + addZero(hours) + ':' + addZero(minutes) + ':' + addZero(seconds);
}
export function addZero(num) {
  return num < 10 ? '0' + num : num
}
